/**************************************************************************************
*
*	Copyright (C) 2010 Brent Andrew O. Chua - See LICENSE.txt for more info.
*		
*	Filename	-	VertexDeclaration.h
*
*	Description -	Vertex declaration for creating custom vertex formats. 
*
*	Comments	-
*
*	Modification History:
*			Name			   Date					Description
*			CodeSushi	-	10/23/2010	-	Creation of this file
**************************************************************************************/

#ifndef _PSX_VERTEX_DECLARATION_H_
#define _PSX_VERTEX_DECLARATION_H_

#include "PulseSTD.h"
#include "GraphicsTypes.h"
#include "ResourcePoolItem.h"
#include "Array.h"

#include <d3d9.h>

namespace Pulse
{
	class VertexDeclaration : public IResourcePoolItem
	{
	public:

		VertexDeclaration( void );

		virtual ~VertexDeclaration( void );

		virtual BOOL CreateResource( void );
		virtual BOOL DestroyResource( void );
		virtual BOOL DisableResource( void );
		virtual BOOL RestoreResource( void );

		virtual BOOL LoadResource( const CHAR *pFilename = NULL );
		virtual BOOL SaveResource( const CHAR *pFilename = NULL );

		virtual EErrorCode::Type Initialize( void );

		virtual void Cleanup( void );

		virtual void AddVertexElement( const VertexElement *pElement );

		virtual void AddVertexElement( const VertexElement *pElements, SIZE_T count );

		virtual void Bind( void );

		virtual void Unbind( void ) { }

		const VertexElement * GetVertexElement( UINT index ) const;

		const VertexElement * GetVertexElement( EVertexElementUsage::Type usage, UINT index = 0 );

		const SIZE_T GetElementCount( void ) const;

	private:

		typedef Array< VertexElement > ElementList;

		ElementList m_elements;

		IDirect3DVertexDeclaration9 *m_pVertexDecl;	// DX9 Vertex declaration

	};

	PSX_INLINE void VertexDeclaration::AddVertexElement( const VertexElement *pElement )
	{
		m_elements.PushBack( *pElement );
		Initialize();
	}

	PSX_INLINE const VertexElement * VertexDeclaration::GetVertexElement( UINT index ) const
	{
		return &m_elements[index];
	}

	PSX_INLINE const SIZE_T VertexDeclaration::GetElementCount( void ) const
	{
		return m_elements.GetSize();
	}

}

#endif /* _PSX_VERTEX_DECLARATION_H_ */